/**三种使用方法：
 * 1）直接在MessageConsumer中设置该类的实例
 * 2）@JmsListener（在onMessage上注解）
 * 3）在Config中配置@Bean，并且在SimpleMessageListenerContainer或DefaultMessageListenerContainer中注入该bean。messageListenerContainer.setMessageListener
 */
package com.example.acitvemqspringbootdemo;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

//@Component
public class MyMessageListener implements MessageListener {
    @Override
//    @JmsListener(destination = "send_reply_queue")
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            try {
                System.out.println("[MessageListener]received:"+((TextMessage) message).getText());
            }
            catch (JMSException ex) {
                throw new RuntimeException(ex);
            }
        }
        else {
            throw new IllegalArgumentException("Message must be of type TextMessage");
        }
    }

}
